package com.yiqi.zhiyuan.feature.mine.presenter;

import com.yiqi.zhiyuan.entity.vo.CarVO;
import com.yiqi.zhiyuan.feature.mine.contract.CarContract;
import com.yiqi.zhiyuan.feature.mine.dependencies.register.DaggerCarPresenterComponent;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * @ProjectName: ZhiYuan
 * @Description: java类作用描述
 * @Author: lijuwen
 * @CreateDate: 2019/3/14 10:54
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/3/14 10:54
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class CarPresenter implements CarContract.Presenter {

    private CarContract.View mView;

    @Inject
    CarContract.Model mModel;


    public CarPresenter(CarContract.View mView) {
        this.mView = mView;
        DaggerCarPresenterComponent.create().inject(this);
    }


    @Override
    public void start() {

    }

    @Override
    public void getDiverCarList() {
        mModel.doGetDiverCarList()
                .compose(mView.bindToLife())
                .subscribe(new Observer<List<CarVO>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
//                        mView.showLoading(d);
                    }

                    @Override
                    public void onNext(List<CarVO> carVOS) {
//                        mView.dismissLoading();
                        if (carVOS != null && !carVOS.isEmpty()) {
                            mView.showDiverCarListSuccess(carVOS);
                        } else {
                            mView.showDiverCarEmpty();
                        }

                    }

                    @Override
                    public void onError(Throwable e) {
//                        mView.dismissLoading();
                        mView.showDiverCarListError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
//                        mView.dismissLoading();
                    }
                });
    }

    @Override
    public void deleteCarInDriver(String ids) {
        mModel.doDeleteCarInDriver(ids)
                .compose(mView.bindToLife())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mView.showLoading(d);
                    }

                    @Override
                    public void onNext(String s) {
                        mView.dismissLoading();
                        mView.showDeleteCarSuccess();
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.dismissLoading();
                        mView.showDeleteCarError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        mView.dismissLoading();
                    }
                });
    }

    @Override
    public void orderQuickSetup(Integer driverId) {
        mModel.doOrderQuickSetup(driverId)
                .compose(mView.<String>bindToLife())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {
//                        mView.showLoading(d);
                    }

                    @Override
                    public void onNext(String homeVo) {
                        mView.dismissLoading();
                        mView.showOrderQuickSetupSuccess();
                    }

                    @Override
                    public void onError(Throwable e) {
//                        mView.dismissLoading();
                        mView.showOrderQuickSetupError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
//                        mView.dismissLoading();
                    }
                });
    }
}
